﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Seller
{
    public partial class wfSubmitOrders : msBsc.Cls.BPDealer
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        private void getDjackeVehicle()
        {
            string vehicleId = this.GetParamHtValue("vehicleId");
            if (string.IsNullOrEmpty(vehicleId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataSet ds = vehicleInfo.SelectByIds("", vehicleId);
                if (ds == null)
                {
                    return;
                }
                DataColumn dc = new DataColumn("VEHICLE_COLOR_NAME");
                ds.Tables[0].Columns.Add(dc);
                ds.Tables[0].Rows[0]["VEHICLE_COLOR_NAME"] = Enum.GetName(typeof(msBsc.AppLogic.DataAlc.cls.CommonEnum.VehicleColorEnum), Convert.ToInt32(ds.Tables[0].Rows[0]["VEHICLE_COLOR"].ToString()));
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"init(" + strJson + ")");
            }
        }

        private void getDjackVehicle()
        {
            string djackId = this.GetParamHtValue("djackId");
            if (string.IsNullOrEmpty(djackId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataSet ds = vehicleInfo.GetVehicleForSubmitOrder(djackId);
                if (ds != null && ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp_vehicle').html();

                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#tl_vlist').html(render);
                            });checkVehicle();");
            }
        }

        private void setOrders()
        {
            string v_OIds = this.GetParamHtValue("oIds");
            if (string.IsNullOrEmpty(v_OIds))
            {
                this.Alert("请选择车辆");
                return;
            }
            string v_startTime = this.GetParamHtValue("startTime");
            if (string.IsNullOrEmpty(v_startTime))
            {
                this.Alert("请选择开始服务时间");
                return;
            }
            string v_stopTime = this.GetParamHtValue("stopTime");
            if (string.IsNullOrEmpty(v_stopTime))
            {
                this.Alert("请选择结束服务时间");
                return;
            }
            string v_service = this.GetParamHtValue("service");
            using (msBsc.AppLogic.DataAlc.CBizOrdersInfo ordersInfo = new msBsc.AppLogic.DataAlc.CBizOrdersInfo())
            {
                string strRet = ordersInfo.AddOrderInfo(v_OIds, v_service, "0", v_startTime, v_stopTime);
                if (strRet != "OK")
                {
                    this.Alert(strRet);
                    return;
                }
                this.ExecJScript(@"alert(""提交订单成功，请尽快联系地接客，以便确认服务！"");window.location.href = "" / "";");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                getDjackeVehicle();
            }
            else if (this.strAction == "getVehicle")
            {
                getDjackVehicle();
            }
            else if (this.strAction == "setOrder")
            {
                setOrders();
            }
        }
    }
}